using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

using Microsoft.Extensions.Configuration;

using NP.BPMReportPlatform.RestfulApis.Dto;
using NP.Enterprise.Utils.ApiResult;

using Volo.Abp.Application.Dtos;

namespace NP.BPMReportPlatform.RestfulApis
{
    public class FinancialPlatformApi : IFinancialPlatformApi
    {
        private readonly BpmReportPlatformHttpClient _httpClient;
        private readonly IConfiguration _configuration;

        public FinancialPlatformApi(BpmReportPlatformHttpClient httpClient,IConfiguration configuration)
        {
            _httpClient = httpClient;
            _configuration = configuration;
        }

        /// <inheritdoc />
        public async Task<List<SapEmployeeDetail>> GetSapEmployeesAsync()
        {
            var remoteServiceUrl = _configuration["FinancialPlatformOptions:RemoteServiceUrl"];
            
            var result = await _httpClient.GetAsync<ApiResult<PagedResultDto<SapEmployeeDetail>>>($"{remoteServiceUrl}api/BaseData/Employee/GetList?SkipCount=1&MaxResultCount=100000&HasDelete=true");

            if (result.Code == 0)
            {
                return result.Result.Items.ToList();
            }
            
            return new List<SapEmployeeDetail>();
        }
    }
}